#include "Shader.h"


Shader::Shader(void)
{
}


Shader::~Shader(void)
{
	Release();
}

void Shader::Render(ID3D11DeviceContext* pd3dImmediateContext, UINT indexCount)
{

    D3DX11_TECHNIQUE_DESC techDesc;
	pd3dImmediateContext->IASetInputLayout(m_VertexLayout);

    m_Technique->GetDesc(&techDesc);
	for(UINT i=0; i<techDesc.Passes; ++i)
    {
        m_Technique->GetPassByIndex(i)->Apply(0, pd3dImmediateContext);
        pd3dImmediateContext->DrawIndexed(indexCount, 0, 0);
    }

}

void Shader::Render(ID3D11DeviceContext* pd3dImmediateContext, CDXUTSDKMesh& i_mesh)
{
	D3DX11_TECHNIQUE_DESC techDesc;
	pd3dImmediateContext->IASetInputLayout(m_VertexLayout);

	m_Technique->GetDesc( &techDesc );
	for( UINT p = 0; p < techDesc.Passes; ++p )
	{
		m_Technique->GetPassByIndex( p )->Apply(0,pd3dImmediateContext);
		i_mesh.Render(pd3dImmediateContext);
	}
}

void Shader::Release()
{
	if(m_VertexLayout)
	{
		m_VertexLayout->Release();
		m_VertexLayout = 0;
	}

	m_Technique = 0;

	if(m_Effect)
	{
		m_Effect->Release();
		m_Effect = 0;
	}
}

ID3DX11Effect* Shader::GetEffect()
{
	return m_Effect;
}

ID3DX11EffectTechnique* Shader::GetTechnique()
{
	return m_Technique;
}

ID3D11InputLayout* Shader::GetVertexLayout()
{
	return m_VertexLayout;
}
